<template>
	<view class="container">
		<view class="user-card">
			<view>
				<view class="user-avatar">
					<u-avatar :src="src" size="120"></u-avatar>
				</view>
				<view class="user-info">
					<view class="user-name">{{agentInfo.name}}</view>
					<view class="user-name">佣金:￥{{agentInfo.money}}</view>
				</view>
			</view>
			<view>
				<!-- <u-icon name="setting" size="40"></u-icon> -->
			</view>
		</view>
		<view class="oper-area">
			<u-cell-group>
				<u-cell-item icon="file-text" title="收支列表" @click = 'getIncome'></u-cell-item>
				<u-cell-item icon="file-text" title="提现记录" @click = 'getdrawal'></u-cell-item>
				<u-cell-item icon="rmb" title="提现" @click = "show = true">
					<u-popup v-model="show" mode="center" width ="80%" height="30%" >
						<view class="popup-txt">请输入提现金额</view>
						<u-input  class="popup-input" v-model="value" type="text" placeholder = "请输入金额" :border="bor" />
						<view class="popup-but">
							<u-button class="" shape="square" size="medium" @click="drawal">提现</u-button>
						</view>
						
					</u-popup>
				</u-cell-item>
				<u-cell-item icon="close-circle-fill" title="退出" @click = 'logout'></u-cell-item>
			</u-cell-group>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				src: 'https://www.duolaibei.com/favicon.ico',
				agentInfo:[],
				show:false,
				value:'',
				bor:true,
				userInfo:[]
			}
		},
		onLoad(options) {
	    uni.showLoading({
				title: '加载中...'
			});
			let that = this;
		  that.userInfo = uni.getStorageSync('userInfo');
			this.getAgentInfo(that.userInfo.id);
		},
		methods: {
			getAgentInfo(agentID){
				let that = this;
				this.$request.httpTokenRequest({
					url: '/admin/agent/getAgentInfo',
					method: 'POST',
					data: {
						agentID: agentID,
					},
				}).then(res => {
					if(res.data.code == 200){
							uni.hideLoading();
							that.agentInfo = res.data.content;
					}else{
						uni.showToast({
							title:res.data.msg,
							icon: 'none',
							duration: 2000,
						})
					}
				},error => {});
			},
			getIncome(){
				uni.navigateTo({
					url: '/pages/center/income' 
				});
			},
			getdrawal(){
				uni.navigateTo({
					url: '/pages/center/drawal' 
				});
			},
			drawal(){
				let that = this;
				this.show = false;
				this.$request.httpTokenRequest({
					url: '/admin/agent/drawal',
					method: 'POST',
					data: {
						agentID: that.userInfo.id,
						money: that.value,
					},
				}).then(res => {
					that.value = '';
					if(res.data.code == 200){
						uni.showToast({
							title:'提现成功，请到提现记录中查看!',
							icon:'success',
							duration:3000
						});
					}else{
						uni.showToast({
							title:res.data.msg,
							icon:'none',
							duration:3000
						});
					}
				},error => {});
				
			},
			logout(){
				var token=uni.getStorageSync('token');
				let that = this;
				this.$request.httpTokenRequest({
					url: '/admin/login/loginOut',
					method: 'POST',
					data: {
						token: token
					},
					// needToken: false,
				}).then(res => {
					if (res.data.code == 200) {
						uni.showToast({
							title:'退出成功',
							icon:'success',
							duration:2000
						});
						uni.clearStorageSync();
					}else{
						uni.showToast({
							title:res.data.msg,
							icon:'none',
							duration:2000
						});
					}
				}, error => {
					
				});
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		height: 100%;
	}

	.container {
		height: 100%;

		.user-card {
			width: 100%;
			height: 8rem;
			//background: $u-type-warning-disabled;
			background: #409EFF;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 2rem 0 1rem;

			view:first-child {
				display: flex;
				align-items: center;

				.user-info {
					margin-left: 2rem;
					.user-name {
						font-size: 1rem;
						line-height: 2rem;
						color: #FFFFFF;
					}
					.user-info {
						font-size: .5rem;
					}
				}
			}
		}

		.oper-area {}
		.popup-txt{
			font-size: 1rem;
			font-weight: 600;
			text-align: center;
			margin: 1rem;
		}
		.popup-input{
			margin: 0 2rem;
		}
		.popup-but{
			margin: 2rem auto;
			text-align: center;
		}
	}
</style>
